package com.mlh.springboot.controller;


import com.mlh.springboot.bean.Furn;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.List;

/**
 * @author 缪林辉
 * @date 2024/3/4 11:19
 * @DESCRIPTION
 */
@Controller
public class DruidSqlController {
    @Resource
    private JdbcTemplate jdbcTemplate;

    @GetMapping("/sql")
    @ResponseBody
    public List<Furn> crudDB(){
        BeanPropertyRowMapper<Furn> furnBeanPropertyRowMapper
                = new BeanPropertyRowMapper<>(Furn.class);
        List<Furn> query = jdbcTemplate.query(
                "select *from `furn`", furnBeanPropertyRowMapper);
        for (Furn furn : query) {
            System.out.println(furn);
        }
        return query;
    }
}
